/*    */ package net.gxf.java2dgame.animation;
/*    */ 
/*    */ import java.awt.Color;
/*    */ import java.awt.Graphics;
/*    */ import java.awt.Graphics2D;
/*    */ import java.awt.Image;
/*    */ import java.awt.Toolkit;
/*    */ import java.io.PrintStream;
/*    */ import javax.swing.ImageIcon;
/*    */ import javax.swing.JPanel;
/*    */ 
/*    */ public class Board extends JPanel
/*    */   implements Runnable
/*    */ {
/*    */   private Image star;
/*    */   private Thread animator;
/*    */   private int x;
/*    */   private int y;
/* 13 */   private final int DELAY = 10;
/*    */ 
/*    */   public Board()
/*    */   {
/* 17 */     setBackground(Color.CYAN);
/* 18 */     setDoubleBuffered(true);
/*    */ 
/* 20 */     ImageIcon ii = new ImageIcon(getClass().getClassLoader().getResource("star.png"));
/* 21 */     this.star = ii.getImage();
/*    */ 
/* 23 */     this.x = (this.y = 10);
/*    */ 
/* 25 */     this.animator = new Thread(this);
/* 26 */     this.animator.start();
/*    */   }
/*    */ 
/*    */   public void paint(Graphics g)
/*    */   {
/* 36 */     super.paint(g);
/*    */ 
/* 38 */     Graphics2D g2d = (Graphics2D)g;
/* 39 */     g2d.drawImage(this.star, this.x, this.y, this);
/* 40 */     Toolkit.getDefaultToolkit().sync();
/* 41 */     g.dispose();
/*    */   }
/*    */ 
/*    */   public void cycle()
/*    */   {
/* 47 */     this.x += 1;
/* 48 */     this.y += 1;
/*    */ 
/* 50 */     if (this.y > 240) {
/* 51 */       this.y = -45;
/* 52 */       this.x = -45;
/*    */     }
/*    */   }
/*    */ 
/*    */   public void run()
/*    */   {
/* 60 */     long beforeTime = System.currentTimeMillis();
/*    */     while (true)
/*    */     {
/* 64 */       cycle();
/* 65 */       repaint();
/*    */ 
/* 67 */       long timeDiff = System.currentTimeMillis() - beforeTime;
/* 68 */       long sleep = 10L - timeDiff;
/*    */ 
/* 70 */       if (sleep < 0L)
/* 71 */         sleep = 2L;
/*    */       try {
/* 73 */         Thread.sleep(sleep);
/*    */       } catch (InterruptedException e) {
/* 75 */         System.out.println("interrupted");
/*    */       }
/*    */ 
/* 78 */       beforeTime = System.currentTimeMillis();
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\DBDownload\lwjglDemo2\lwjglDemo2\Run.jar
 * Qualified Name:     com.java2dgame.animation.Board
 * JD-Core Version:    0.6.2
 */